home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 6 / develop 6 code / TCP / NewsWatcher / NewsWatcher 2.0d15 source / source / child.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-17  |  2.5 KB  |  106 lines  |  [TEXT/KAHL]

  1. /*----------------------------------------------------------------------------
  2.  
  3.     child.c
  4.  
  5.     This module manages the parent/child window relationship
  6.     
  7.     Portions copyright © 1990, Apple Computer.
  8.     Portions copyright © 1993, Northwestern University.
  9.  
  10. ----------------------------------------------------------------------------*/
  11.  
  12. #include "glob.h"
  13. #include "child.h"
  14. #include "util.h"
  15.  
  16.  
  17. /*    AddChild adds a child window to the windowlist of a parent
  18.     Windows with associated child windows will close
  19.     their children when closed
  20. */
  21.  
  22. void AddChild (WindowPtr parent, WindowPtr child)
  23. {
  24.     TWindow **parentInfo;
  25.     TChild **newChild;
  26.     
  27.     parentInfo = (TWindow**) GetWRefCon(parent);
  28.     
  29.     newChild = (TChild**) MyNewHandle(sizeof(TChild));
  30.     if (MyMemErr() != noErr)
  31.         return;
  32.     (**newChild).childWindow = child;
  33.     (**newChild).next = (**parentInfo).childList;
  34.     (**parentInfo).childList = newChild;
  35. }
  36.  
  37.  
  38. /* Removes a child window from the windowlist of a parent
  39. */
  40.  
  41. void RemoveChild (WindowPtr parent, WindowPtr child)
  42. {
  43.     TWindow **parentInfo;
  44.     TChild **current,**prev;
  45.     
  46.     if (parent == nil) return;
  47.     parentInfo = (TWindow**) GetWRefCon(parent);
  48.     for (current = prev = (**parentInfo).childList;
  49.         current != nil && (**current).childWindow != child;
  50.         prev = current,current = (**current).next)
  51.         ;
  52.     if (current) {
  53.         if (prev == current) {
  54.             (**parentInfo).childList = (**current).next;
  55.         } else {
  56.             (**prev).next = (**current).next;
  57.         }
  58.         MyDisposHandle((Handle)current);
  59.     }
  60. }
  61.  
  62.  
  63. /*    FindChildByCellData locates an open child window corresponding to
  64.     the cell data (index into group or subject array) of a cell in a
  65.     list window. */
  66.     
  67. WindowPtr FindChildByCellData (WindowPtr wind, short cellData)
  68. {
  69.     TWindow **info,**childInfo;
  70.     TChild **childListRec;
  71.     WindowPtr child;
  72.     EWindowKind kind;
  73.     
  74.     info = (TWindow**)GetWRefCon(wind);
  75.     kind = (**info).kind;
  76.     for (childListRec = (**info).childList; childListRec != nil; 
  77.         childListRec = (**childListRec).next) 
  78.     {
  79.         child = (**childListRec).childWindow;
  80.         childInfo = (TWindow**)GetWRefCon(child);
  81.         if (kind == kSubject) {
  82.             if ((**childInfo).parentSubject == cellData) return child;
  83.         } else {
  84.             if ((**childInfo).parentGroup == cellData) return child;
  85.         }
  86.     }
  87.     return nil;
  88. }
  89.  
  90.  
  91. /*    FindChild locates an open child window corresponding to a cell in a 
  92.     list window. */
  93.     
  94. WindowPtr FindChild (WindowPtr wind, Cell theCell)
  95. {
  96.     TWindow **info;
  97.     ListHandle theList;
  98.     short cellData, cellDataLen;
  99.     
  100.     info = (TWindow**)GetWRefCon(wind);
  101.     theList = (**info).theList;
  102.     cellDataLen = 2;
  103.     LGetCell(&cellData, &cellDataLen, theCell, theList);
  104.     return FindChildByCellData(wind, cellData);
  105. }
  106.